/*

This file sets up results for 2nd disclosure review

*/

use "/projects/data/dataSTATA/combined/combined_productivity_energy_4digit_4m.dta", clear

* drop obs that would be excluded from regressions --> generate constant sample
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

reghdfe lelec_price_init instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

gen age = year - firstyear

*>--------- define rounding function for regs---------------------<
* copied from rounding_regs.do Census file provided

capture program drop round
program define round, eclass
   mat A = e(b)
   forval j = 1/`=colsof(matrix(A))' { 
      mat A[1,`j'] = round(A[1,`j'],10^(floor(log10(abs(A[1,`j'])))-3))
   } 
   ereturn repost b = A

   if e(N)>=15&e(N)<=99 ereturn scalar N = round(e(N), 10)
   if e(N)>=100&e(N)<=999 ereturn scalar N = round(e(N), 50)
   if e(N)>=1000&e(N)<=9999 ereturn scalar N = round(e(N), 100)
   if e(N)>=10000&e(N)<=99999 ereturn scalar N = round(e(N), 500)
   if e(N)>=100000&e(N)<=999999 ereturn scalar N = round(e(N), 1000)
   if e(N)>=1000000 ereturn scalar N = round(e(N),10^(floor(log10(e(N)))-3))

   if e(N)<15 {
   scalar N_less15=1
   ereturn scalar N=.
   }

   if e(df_r)>=15&e(df_r)<=99 ereturn scalar df_r = round(e(df_r), 10)
   if e(df_r)>=100&e(df_r)<=999 ereturn scalar df_r = round(e(df_r), 50)
   if e(df_r)>=1000&e(df_r)<=9999 ereturn scalar df_r = round(e(df_r), 100)
   if e(df_r)>=10000&e(df_r)<=99999 ereturn scalar df_r = round(e(df_r), 500)
   if e(df_r)>=100000&e(df_r)<=999999 ereturn scalar df_r = round(e(df_r), 1000)
   if e(df_r)>=1000000 ereturn scalar df_r = round(e(df_r),10^(floor(log10(e(df_r)))-3))

   if e(df_r)<15 {
   scalar df_less15=1
   ereturn scalar df_r=.
   }


   capture ereturn scalar r2 = round(e(r2),10^(floor(log10(e(r2)))-3))
   capture ereturn scalar r2_a = round(e(r2_a),10^(floor(log10(e(r2_a)))-3))
   capture ereturn scalar F = round(e(F),10^(floor(log10(e(F)))-3))
   capture ereturn scalar rmse = round(e(rmse),10^(floor(log10(e(rmse)))-3))
   capture ereturn scalar mss = round(e(mss),10^(floor(log10(e(mss)))-3))
   capture ereturn scalar rss = round(e(rss),10^(floor(log10(e(rss)))-3))
   capture ereturn scalar rkf = round(e(rkf),10^(floor(log10(e(rkf)))-3))

end

*>------------------------------ Table A.1 ---------------------<

* full sample and electricity intensive industries -- energy outcomes
preserve
mat M = J(21, 2,.)

* round numerators and denominators for variables where that are ratios
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 firstyear year ee pe elec_price_init tvs co2_int_i_both btu_int_i_both
gen  elec_price_round = ee / pe 
gen  elec_int_round = pe / tvs

* Sum Stats Col 1 -- All Industries
sum year
gen mean_year = `r(mean)'
gen se_year   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_year se_year
sum mean_year 
mat M[1,1] = `r(mean)'
sum se_year
mat M[2,1] = (`r(mean)')

sum firstyear
gen mean_firstyear = `r(mean)'
gen se_firstyear   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_firstyear se_firstyear
sum mean_firstyear 
mat M[3,1] = `r(mean)'
sum se_firstyear
mat M[4,1] = (`r(mean)')

sum age
gen mean_age = `r(mean)'
gen se_age   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_age se_age
sum mean_age
mat M[5,1] = `r(mean)'
sum se_age
mat M[6,1] = (`r(mean)')

sum elec_price_round
gen mean_elecprice = `r(mean)'
gen se_elecprice   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elecprice se_elecprice
sum mean_elecprice 
mat M[7,1] = `r(mean)'
sum se_elecprice
mat M[8,1] = (`r(mean)')

sum elec_price_init
gen mean_elecprice_init = `r(mean)'
gen se_elecprice_init   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elecprice_init se_elecprice_init
sum mean_elecprice_init 
mat M[9,1] = `r(mean)'
sum se_elecprice_init
mat M[10,1] = (`r(mean)')

sum elec_int_round
gen mean_elec_int = `r(mean)'
gen se_elec_int   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elec_int se_elec_int
sum mean_elec_int
mat M[11,1] = `r(mean)'
sum se_elec_int
mat M[12,1] = (`r(sd)')

sum co2_int_i_both 
gen mean_co2_iboth = `r(mean)'
gen se_co2_iboth   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_co2_iboth se_co2_iboth
sum mean_co2_iboth
mat M[13,1] = `r(mean)'
sum se_co2_iboth
mat M[14,1] = (`r(mean)')

sum btu_int_i_both
gen mean_btu_iboth = `r(mean)'
gen se_btu_iboth   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_btu_iboth se_btu_iboth
sum mean_btu_iboth
mat M[15,1] = `r(mean)'
sum se_btu_iboth
mat M[16,1] = (`r(mean)')

sum ee
gen mean_ee = `r(mean)'
gen se_ee   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_ee se_ee
sum mean_ee
mat M[17,1] = `r(mean)'
sum se_ee
mat M[18,1] = (`r(mean)')

sum pe
gen mean_pe = `r(mean)'
gen se_pe   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_pe se_pe
sum mean_pe
mat M[19,1] = `r(mean)'
sum se_pe
mat M[20,1] = (`r(mean)')

sum firstyear
gen N = `r(N)'
do /projects/programs/codeSTATA/B_analysis/rounding_N.do N
sum N
mat M[21,1] = `r(mean)'

* Sum stats Col 2 -- electricity-intensive industries
keep if elec_perc_ind > 0.7
sum year
gen mean_year2 = `r(mean)'
gen se_year2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_year2 se_year2
sum mean_year2 
mat M[1,2] = `r(mean)'
sum se_year2
mat M[2,2] = (`r(mean)')

sum firstyear
gen mean_firstyear2 = `r(mean)'
gen se_firstyear2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_firstyear2 se_firstyear2
sum mean_firstyear2
mat M[3,2] = `r(mean)'
sum se_firstyear2
mat M[4,2] = (`r(mean)')

sum age
gen mean_age2 = `r(mean)'
gen se_age2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_age2 se_age2
sum mean_age2
mat M[5,2] = `r(mean)'
sum se_age2
mat M[6,2] = (`r(mean)')

sum elec_price_round
gen mean_elecprice2 = `r(mean)'
gen se_elecprice2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elecprice2 se_elecprice2
sum mean_elecprice2 
mat M[7,2] = `r(mean)'
sum se_elecprice2
mat M[8,2] = (`r(mean)')

sum elec_price_init
gen mean_elecprice_init2 = `r(mean)'
gen se_elecprice_init2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elecprice_init2 se_elecprice_init2
sum mean_elecprice_init2 
mat M[9,2] = `r(mean)'
sum se_elecprice_init2
mat M[10,2] = (`r(mean)')

sum elec_int_round
gen mean_elec_int2 = `r(mean)'
gen se_elec_int2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elec_int2 se_elec_int2
sum mean_elec_int2
mat M[11,2] = `r(mean)'
sum se_elec_int2
mat M[12,2] = (`r(sd)')

sum co2_int_i_both 
gen mean_co2_iboth2 = `r(mean)'
gen se_co2_iboth2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_co2_iboth2 se_co2_iboth2
sum mean_co2_iboth2
mat M[13,2] = `r(mean)'
sum se_co2_iboth2
mat M[14,2] = (`r(mean)')

sum btu_int_i_both
gen mean_btu_iboth2 = `r(mean)'
gen se_btu_iboth2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_btu_iboth2 se_btu_iboth2
sum mean_btu_iboth2
mat M[15,2] = `r(mean)'
sum se_btu_iboth2
mat M[16,2] = (`r(mean)')

sum ee
gen mean_ee2 = `r(mean)'
gen se_ee2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_ee2 se_ee2
sum mean_ee2
mat M[17,2] = `r(mean)'
sum se_ee2
mat M[18,2] = (`r(mean)')

sum pe
gen mean_pe2 = `r(mean)'
gen se_pe2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_pe2 se_pe2
sum mean_pe2
mat M[19,2] = `r(mean)'
sum se_pe2
mat M[20,2] = (`r(mean)')

sum firstyear
gen N2 = `r(N)'
do /projects/programs/codeSTATA/B_analysis/rounding_N.do N2
sum N2
mat M[21,2] = `r(mean)'

set linesize 255
svmat M
format M* %25.2f
keep M*
matrix colnames M = All_Industries Electricity_Intensive_Industries
matrix rownames M = Year se Entry_Year se Age se Current_Electricity_Price se Initial_Electricity_Price se Electricity_Intensity se CO2_Intensity se BTU_Intensity se Cost_of_Purchased_Electricity se Quantity_of_Electricity se N
esttab matrix(M) using "/projects/results/tables/summary_stats_wSE.xls", replace
	
restore


*>------------------- summary statistics for paper text -----------------------<
preserve
mat M = J(4, 1,.)

* number of imputed capital obs
sum iks_i if mi(ks_i)
gen N_missingK = `r(N)'
do /projects/programs/codeSTATA/B_analysis/rounding_N.do N_missingK
sum N_missingK
mat M[1,1] = `r(mean)'

* electricity expenditures as fraction of tot energy expenditures ($)
sum elec_perc
gen mean_elec_perc = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2.do mean_elec_perc
sum mean_elec_perc
mat M[2,1] = `r(mean)'

* electricity energy as fraction of tot energy consumption (BTU)

do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 pe tvs btu_int_i_both ge 

gen elec_btu = (pe * 1000 *  3412.14) / 1000000
gen elec_btu_sh = elec_btu / (btu_int_i_both * tvs * 1000)
sum elec_btu_sh

gen mean_elec_btu_sh = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elec_btu_sh
sum mean_elec_btu_sh
mat M[3,1] = `r(mean)'

drop elec_btu_sh elec_btu

* share of electricity generated on-site 
gen on_sh = ge / (ge + pe)
sum on_sh

gen mean_on_sh = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_on_sh
sum mean_on_sh
mat M[4,1] = `r(mean)'

drop on_sh

set linesize 255
svmat M
format M* %25.2f
keep M*
matrix colnames M = Mean
matrix rownames M = Obs_Missing_K Elec_Expenditure_Share Elec_BTU_Share Onsite_Gen_Share
esttab matrix(M) using "/projects/results/tables/summary_stats_forText.xls", replace

restore

*>----------------- Table A.3 -----------------------------------<

preserve
mat M = J(11, 2,.)

* Column 1 : All Industries

* average fraction of entrants/exiters
sum entrant
gen mean_entrant = `r(mean)'
gen se_entrant   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_entrant se_entrant
sum mean_entrant
mat M[1,1] = `r(mean)'
sum se_entrant
mat M[2,1] = (`r(mean)')

sum exit
gen mean_exit = `r(mean)'
gen se_exit   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_exit se_exit
sum mean_exit
mat M[3,1] = `r(mean)'
sum se_exit
mat M[4,1] = (`r(mean)')

* by year -- make this a histogram?
* bys year: sum entrant exit

* average obs by plant
bys lbdnum: gen n_obs = _n
sum n_obs
gen mean_n_obs = `r(mean)'
gen se_n_obs   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_n_obs se_n_obs
sum mean_n_obs
mat M[5,1] = `r(mean)'
sum se_n_obs
mat M[6,1] = (`r(mean)')

* average age
sum age
gen mean_age = `r(mean)'
gen se_age   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_age se_age
sum mean_age
mat M[7,1] = `r(mean)'
sum se_age
mat M[8,1] = (`r(mean)')

* average age at exit
gen age_at_exit = lastyear - firstyear if !mi(lastyear)
sum age_at_exit
gen mean_age_at_exit = `r(mean)'
gen se_age_at_exit   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_age_at_exit se_age_at_exit
sum mean_age_at_exit
mat M[9,1] = `r(mean)'
sum se_age_at_exit
mat M[10,1] = (`r(mean)')

sum age 
gen N = `r(N)'
do /projects/programs/codeSTATA/B_analysis/rounding_N.do N
sum N
mat M[11,1] = `r(mean)'

* Sum stats Col 2 -- electricity-intensive industries
keep if elec_perc_ind > 0.7

* average fraction of entrants/exiters
sum entrant
gen mean_entrant2 = `r(mean)'
gen se_entrant2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_entrant2 se_entrant2
sum mean_entrant2
mat M[1,2] = `r(mean)'
sum se_entrant2
mat M[2,2] = (`r(mean)')

sum exit
gen mean_exit2 = `r(mean)'
gen se_exit2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_exit2 se_exit2
sum mean_exit2
mat M[3,2] = `r(mean)'
sum se_exit2
mat M[4,2] = (`r(mean)')

* average obs by plant
bys lbdnum: gen n_obs2 = _n
sum n_obs2
gen mean_n_obs2 = `r(mean)'
gen se_n_obs2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_n_obs2 se_n_obs2
sum mean_n_obs2
mat M[5,2] = `r(mean)'
sum se_n_obs2
mat M[6,2] = (`r(mean)')

* average age
sum age
gen mean_age2 = `r(mean)'
gen se_age2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_age2 se_age2
sum mean_age2
mat M[7,2] = `r(mean)'
sum se_age2
mat M[8,2] = (`r(mean)')

* average age at exit
sum age_at_exit
gen mean_age_at_exit2 = `r(mean)'
gen se_age_at_exit2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_age_at_exit2 se_age_at_exit2
sum mean_age_at_exit2
mat M[9,2] = `r(mean)'
sum se_age_at_exit2
mat M[10,2] = (`r(mean)')

sum age 
gen N2 = `r(N)'
do /projects/programs/codeSTATA/B_analysis/rounding_N.do N2
sum N2
mat M[11,2] = `r(mean)'

set linesize 255
svmat M
format M* %25.2f
keep M*
matrix colnames M = All_Industries Electricity_Intensive_Industries
matrix rownames M = Entrant_Fraction se Exit_Fraction se Plant_Obs se Age se Age_at_Exit se N
esttab matrix(M) using "/projects/results/tables/summary_stats_exit.xls", replace

restore

*>------------------- Table A.6 ------------------------------------------<
* total value of shipments (1000s USD)
ivreghdfe ltvs  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

* total co2 (both)
gen lco2_i = log(1+co2_int_i_both * tvs * 1000)
ivreghdfe lco2_i  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

* total btu (both)
gen lbtu_i = log(1+btu_int_i_both * tvs * 1000)
ivreghdfe lbtu_i  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/otheroutcomes_2.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Revenue" "Total CO2" "Total CO2, No Interpolation" "Total BTU" "Total BTU, No Interpolation" ) coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)

eststo clear 


*>--------------------- Table 4 ---------------------------------<

* reduced form

reghdfe we_scale instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

reghdfe we_scale instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

reghdfe wh instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

reghdfe wh instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/results/tables/reducedform_productivity.xls", b(3) se(3) obslast nonumbers replace star(* 0.10 ** 0.05 *** 0.01) keep(instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init) mgroups("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec-Intensive Industries"  , pattern(1 1 1 1 )) coeflabels(instr_B_cl Coal_ShareXCurrent_Coal_Price instr_B_ng Natural_Gas_ShareXCurrent_Natural_Gas_Price instr_B_pa Petroleum_ShareXCurrent_Petroleum_Price instr_B_cl_init Coal_ShareXInitial_Coal_Price instr_B_ng_init Natural_Gas_ShareXInitial_Natural_Gas_Price instr_B_pa_init Petroleum_ShareXInitial_Petroleum_Price)
eststo clear 

*>----------------- Table 5 ------------------------------------------------<

* OLS
reghdfe we_scale  lelec_price lelec_price_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
reghdfe we_scale  lelec_price lelec_price_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
reghdfe wh  lelec_price lelec_price_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
reghdfe wh  lelec_price lelec_price_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

* IV
ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe we_scale (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/results/tables/ols_iv_productivity.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mgroups("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries" "Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries" , pattern(1 1 1 1 1 1 1 1 )) coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear 


*>--------------------------- Table 6 --------------------------<

* age
ivreghdfe we_scale  (lelec_price c.age#c.lelec_price_init lelec_price_init= instr_B_cl instr_B_ng instr_B_pa  c.age#c.instr_B_cl_init instr_B_cl_init c.age#c.instr_B_ng_init  instr_B_ng_init c.age#c.instr_B_pa_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

ivreghdfe we_scale  (lelec_price c.age#c.lelec_price_init lelec_price_init= instr_B_cl instr_B_ng instr_B_pa  c.age#c.instr_B_cl_init instr_B_cl_init c.age#c.instr_B_ng_init  instr_B_ng_init c.age#c.instr_B_pa_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

ivreghdfe wh  (lelec_price c.age#c.lelec_price_init lelec_price_init= instr_B_cl instr_B_ng instr_B_pa  c.age#c.instr_B_cl_init instr_B_cl_init c.age#c.instr_B_ng_init  instr_B_ng_init c.age#c.instr_B_pa_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

ivreghdfe wh (lelec_price c.age#c.lelec_price_init lelec_price_init= instr_B_cl instr_B_ng instr_B_pa  c.age#c.instr_B_cl_init instr_B_cl_init c.age#c.instr_B_ng_init  instr_B_ng_init c.age#c.instr_B_pa_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/heterogeneity_age_productivity.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init c.age#c.lelec_price_init) mgroups("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries" , pattern(1 1 1 1 )) coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price) c.age#c.lelec_price_init log(Initial_Electricity_Price)XAge) scalars("rkf K-P F stat") sfmt(1)
eststo clear 



*>------------------------ Table A.9 -----------------------------------------<

* year x industry, first year x industry, state x industry FE
ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.bestnaics i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe we_scale (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.bestnaics i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.bestnaics i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe wh (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.bestnaics i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/results/tables/robustness_productivity.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title(" year x industry, first year x industry, state x industry FE") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear

* unweighted
ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) , absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) , absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) , absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) , absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round 

esttab using "/projects/results/tables/robustness_productivity.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("Unweighted") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear

* state x year trends
ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics c.year##i.fipsst) cluster(fipsst)
eststo: round
ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics c.year##i.fipsst) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics c.year##i.fipsst) cluster(fipsst)
eststo: round
ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics c.year##i.fipsst) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/results/tables/robustness_productivity.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("state x year trends") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear

* co2, btu excluding imputed values
preserve
ivreghdfe lco2_int_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics ) cluster(fipsst)
keep if e(sample)

ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics ) cluster(fipsst)
eststo: round

ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics ) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/results/tables/robustness_productivity.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("co2, btu excluding imputed values") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear
restore

* without ASM Fuels Trailers
preserve
ivreghdfe lco2_int_i  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample) 

ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe wh  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
esttab using "/projects/results/tables/robustness_productivity.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("co2, btu excluding ASM Fuels Trailers") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear
restore

* without ASM Fuels Trailers or Imputed Values
preserve
ivreghdfe lco2_int (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

ivreghdfe we_scale  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

ivreghdfe wh (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

ivreghdfe wh (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/results/tables/robustness_productivity.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("co2, btu excluding ASM Fuels Trailers and imputed values") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear
restore



*>--------------------- Table A.5 -----------------<


preserve
mat M = J(4, 5,.)

* round 
do   /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 sig nu b_k b_e rho_e b_h rho_h


sum sig
gen mean_sig = `r(mean)'
gen se_sig2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_sig se_sig2
sum mean_sig
mat M[1,1] = `r(mean)'
sum se_sig2
mat M[2,1] = (`r(mean)')

sum nu
gen mean_nu = `r(mean)'
gen se_nu2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_nu se_nu2
sum mean_nu
mat M[1,2] = `r(mean)'
sum se_nu2
mat M[2,2] = (`r(mean)')

sum b_k
gen mean_b = `r(mean)'
gen se_b   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_b se_b
sum mean_b
mat M[1,3] = `r(mean)'
sum se_b
mat M[2,3] = (`r(mean)')


sum rho_e
gen mean_rhoe = `r(mean)'
gen se_rhoe   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_rhoe se_rhoe
sum mean_rhoe
mat M[1,4] = `r(mean)'
sum se_rhoe
mat M[2,4] = (`r(mean)')

sum rho_h
gen mean_rhoh = `r(mean)'
gen se_rhoh   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_rhoh se_rhoh
sum mean_rhoh
mat M[1,5] = `r(mean)'
sum se_rhoh
mat M[2,5] = (`r(mean)')

* Sum stats Celectricity-intensive industries
keep if elec_perc_ind > 0.7
drop mean_sig se_sig2 mean_nu se_nu2 mean_b se_b mean_rhoe se_rhoe mean_rhoh se_rhoh

sum sig
gen mean_sig = `r(mean)'
gen se_sig2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_sig se_sig2
sum mean_sig
mat M[3,1] = `r(mean)'
sum se_sig2
mat M[4,1] = (`r(mean)')

sum nu
gen mean_nu = `r(mean)'
gen se_nu2   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_nu se_nu2
sum mean_nu
mat M[3,2] = `r(mean)'
sum se_nu2
mat M[4,2] = (`r(mean)')

sum b_k
gen mean_b = `r(mean)'
gen se_b   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_b se_b
sum mean_b
mat M[3,3] = `r(mean)'
sum se_b
mat M[4,3] = (`r(mean)')

sum rho_e
gen mean_rhoe = `r(mean)'
gen se_rhoe   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_rhoe se_rhoe
sum mean_rhoe
mat M[3,4] = `r(mean)'
sum se_rhoe
mat M[4,4] = (`r(mean)')

sum rho_h
gen mean_rhoh = `r(mean)'
gen se_rhoh   = `r(sd)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_rhoh se_rhoh
sum mean_rhoh
mat M[3,5] = `r(mean)'
sum se_rhoh
mat M[4,5] = (`r(mean)')

set linesize 255
svmat M
format M* %25.2f
keep M*
matrix colnames M = Mean_Sig Mean_Nu Mean_Beta_K Mean_Rho_e Mean_Bh 
matrix rownames M = All_Industries se Elec_Int_Industries se
esttab matrix(M) using "/projects/results/tables/params_summary.xls", replace

restore


